//http://www.a559.com/htm/piclist1/12.htm?zq=3
function testt(ao) {
    if($("#s_url").val()!=$("#this_url").val()){
        loadset();
    }
    if(ao==1) {
        $.ajax({
            type: 'post',
            async: true,//true是异步，false是同步
            timeout: 20000,//20秒
            url: "/collect/reset/longsun_collect_set.php?b1=1&XDEBUG_SESSION_START=5552", //"?rn="+Math.random(),  //网址请以/开头否则可能不带cookies过去
            data: $("#cpform").serialize(),
            dataType: "html",//html,text,json,jsonp,excel,script
            success: function (data) {
                testt2(ao)
            }
        });
    }else{
        testt2(ao);
    }
}

function testt2(ao){

    $.ajax({
        type: 'post',
        async: true,//true是异步，false是同步
        timeout: 20000,//20秒
        url: "/collect/reset/json.php", //"?rn="+Math.random(),  //网址请以/开头否则可能不带cookies过去
        data: {url: $("#s_url").val(), prodata: $("#prodata").val(), prowebdata: $("#prowebdata").val(), saveFilters: 1},  //$("form").serialize()
        dataType: "json",//html,text,json,jsonp,excel,script
        success: function (data) {
            layer.msg("专业数据已经更新！");
        }
    });

    $("#subject").val("");
    $("#uchome-ttHtmlEditor").html("");
    $("#uchome-ifrHtmlEditor", document.body).contents().find("body").html("");
    nozqnr = ($("#nozqnr").is(":checked") && o.gather_type.value == 6) ? 1 : 0;
    zwnozqnr = ($("#zwnozqnr").is(":checked") && o.gather_type.value == 1) ? 1 : 0;
    dostop();
    doatest(o.url.value, ao);
}


function azq(ao) {
    //$(ao).parent(".ah").hide();
    $(ao).html("抓取<img style=\"position: absolute;left:0em;z-index:2\" src='/collect/loading.gif'>");
    o.url.value = $(ao).parents("tr").children(".listurl").text();
    o.gindex.value = $(ao).parents("tr").children(".gindex").text();
    o.host.value = $(ao).parents("tr").children(".pthost").text();
    $("select[name='ptid']").val($(ao).parents("tr").children(".ptid").text());
    o.tid.value = $(ao).parents("tr").children(".tid").text();
    qk();
    testt(ao);
}

function atestzq(ao) {
    o.url.value = o.alisturl.value;
    o.gindex.value = o.agindex.value;
    o.host.value = o.pthost.value;
    o.ptid.value = o.aptid.value;
    o.tid.value = o.atid.value;
    qk();
    testt();
}

function aselect(ao) {
    o.alisturl.value = $(ao).parents("tr").children(".listurl").text();
    o.agindex.value = $(ao).parents("tr").children(".gindex").text();
    $("select[name='aptid']").val($(ao).parents("tr").children(".ptid").text());
    o.pthost.value = $(ao).parents("tr").children(".pthost").text();
    o.aptid.value = $(ao).parents("tr").children(".ptid").text();
    o.aptusername.value = $(ao).parents("tr").children(".aptusername").text();
    o.atid.value = $(ao).parents("tr").children(".tid").text();
}

function uselect(ao) {
    if (o.pthost.value == o.upthost.value) {
        o.aptusername.value = $(ao).parents("tr").children(".uusername").text();
    } else {
        alert('该用户不是' + o.pthost.value + '的用户');
    }
}

function adel(id) {
    ifr.location = "reset.php?a=adel&id=" + id;
}

function udel(id) {
    ifr.location = "reset.php?a=udel&id=" + id;
}

function addautos() {
    $.post("reset.php", $(o).serializeArray(), function (data, textStatus) {
        o.sB1.click();
    });
}

function adduassss() {
    $.post("reset.php?addupasss=1", $(o).serializeArray(), function (data, textStatus) {
        o.sB1.click();
    });
}

function ashow(host, ptid, tid) {
    if (ptid == 2) {
        window.open("http://" + host + "/index.php?m=content&c=index&a=lists&catid=" + tid);
    }
}


function plzqs() {
//                            $.post("reset.php?plzq=1", $(o).serializeArray(), function(data,textStatus){
//                                alert("抓取完成"+data);
//                            });
    var ydata;
    var jo;
    $(".azq").each(function () {
        //this.click();
        jo = $(this);
        jo.parent(".ah").hide();
        jo.html("抓取<img style=\"position: absolute;left:0em;z-index:2\" src='/collect/loading.gif'>");


        ydata = new Array();
        ydata['s_url'] = jo.parents("tr").children(".listurl").text();
        ydata['gindex'] = jo.parents("tr").children(".gindex").text();
        ydata['host'] = jo.parents("tr").children(".pthost").text();
        ydata['ptusername'] = jo.parents("tr").children(".ptusername").text();
        ydata['ptpassword'] = jo.parents("tr").children(".ptpassword").text();
        ydata['ptid'] = jo.parents("tr").children(".ptid").text();
        ydata['tid'] = jo.parents("tr").children(".tid").text();
        ydata['bfid'] = jo.parents("tr").find("span").html();
        url = "reset_send.php?onlyread=1&gather_type=6&code=&cookie=&s=" + Math.random();
        $.ajax({
            type: 'POST',
            async: true,
            url: url,
            s_url: ydata['s_url'],
            data: {
                s_url: ydata['s_url'],
                gindex: ydata['gindex'],
                host: ydata['host'],
                ptusername: ydata['ptusername'],
                ptid: ydata['ptid'],
                tid: ydata['tid'],
                ptpassword: ydata['ptpassword'],
                bfid: ydata['bfid']
            },
            dataType: "json",
            success: function (data) {
                $("#B2").removeAttr("disabled");
                jo = $("#bfida" + data.bfid);
                jo.html("抓取");
                jo.parent("td").find(".ah").show();
                $("#subject").val(data.subject);
                $("#uchome-ttHtmlEditor").val(data.message);
                if ($("#pbliu").attr("checked")) {
                    var json = new Array();
                    var patt = new RegExp("\[img\]([^<>]+)\[\/img\]", "gi");
                    var result;
                    while ((result = patt.exec(data.message)) != null) {
                        json[json.length]['image'] = result;
                        json[json.length]['subject'] = data.subject;
                        json[json.length]['url'] = data.url;
                    }
                    loadMore(json);
                } else {
                    data.message = data.message.replace(/\r?\n/gi, "<p>");
                    data.message = data.message.replace(/\[align=center\]/gi, "<p align=center>");
                    data.message = data.message.replace(/\[align=left\]/gi, "<p align=left>");
                    data.message = data.message.replace(/\[\/align\]/gi, "</p>");
                    data.message = data.message.replace(/\[img\](.*)\[\/img\]/gi, "<p align=center><img src=\"$1\"></p>");
                    data.message = data.message.replace(/\[img\]/gi, "<img src=\"");
                    data.message = data.message.replace(/\[\/img\]/gi, "\">");
                    data.message = data.message.replace(/\[b\]([^\[\]]*)\[\/b\]/gi, "<b>$1</b>");
                    data.message = data.message.replace(/\[b\]|\[\/b\]/gi, "");
                    $("#uchome-ifrHtmlEditor", document.body).contents().find("body").html(data.message);
                }
            }
        });
    });

}

function qk() {
    $("#subject").val("");
    $("#uchome-ttHtmlEditor").val("");
    $("#uchome-ifrHtmlEditor", document.body).contents().find("body").html("");
}

function addsle() {
    $("#addsletr").addClass("totop");
}

function zk(o) {
    if ($(".zk").css("display") == "none") {
        $(".zk").show();
        $(o).text("-隐藏");


    } else {
        $(".zk").hide()
        $(o).text("+展开");

    }
}

window.imgCode = -1;
(function () {
    function checkSNUID() {
        var cookieArr = document.cookie.split('; '),
            count = 0;

        for (var i = 0, len = cookieArr.length; i < len; i++) {
            if (cookieArr[i].indexOf('SNUID=') > -1) {
                count++;
            }
        }

        return count > 1;
    }

    if (checkSNUID()) {
        var date = new Date(), expires;
        date.setTime(date.getTime() - 100000);
        expires = date.toGMTString();
        document.cookie = 'SNUID=1;path=/;expires=' + expires;
    }


})();

function setImgCode(code) {
    try {
        var t = new Date().getTime() - imgRequestTime.getTime();
    } catch (e) {
    }
    window.imgCode = code;
}

function changeImg2() {
    var t = new Date().getTime().toString();
    $("#tc").val(t)
    $.ajax({
        type: 'post',
        async: true,//true是异步，false是同步
        timeout: 20000,//20秒
        url: "/collect/createyzm.php?XDEBUG_SESSION_START=" + t + "&seccodeImage=" + encodeURIComponent($("#seccodeImage").attr("src_")) + "&rn=" + Math.random(), //"?rn="+Math.random(),  //网址请以/开头否则可能不带cookies过去
        data: $("form").serialize(),
        dataType: "json",//html,text,json,jsonp,excel,script
        success: function (data) {
            var src = $("#seccodeImage").attr("src");
            src = src.replace(/tc=[0-9]+/gi, "tc=" + t);
            $("#seccodeImage").attr("src", src);
            var src_ = $("#seccodeImage").attr("src_");
            src_ = src_.replace(/tc(=|%3D)[0-9]+/gi, "tc=" + t);
            $("#seccodeImage").attr("src_", src_);
            if (window.event) {
                window.event.returnValue = false
            }
        }
    });
}

$(document).on("click", "#fsyzm", function () {
    var t = new Date().getTime().toString();
    $.ajax({
        type: 'post',
        async: true,//true是异步，false是同步
        timeout: 20000,//20秒
        url: "/collect/fsyzm.php?XDEBUG_SESSION_START=" + t, //"?rn="+Math.random(),  //网址请以/开头否则可能不带cookies过去
        data: $("form").serialize(),
        dataType: "json",//html,text,json,jsonp,excel,script
        success: function (data) {
            if (!/错误|不正确|失败/gi.test(data.regMsg)) {
                layer.msg(data.regMsg);
                debugger;
                qk();
            } else {
                layer.msg(data.regMsg);
                changeImg2();
                return false;
            }
        }
    });
});

function setcookie(name, value) {
    var Days = 30;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

function getcookie(name) {
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) {
        return (arr[2]);
    } else {
        return "";
    }
}

function delcookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getcookie(name);
    if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}


var viid = 0;
var page = 1;
var nozqnr = 0;
var zwnozqnr = 0;
var index;
var ajaxGet = null;
var layerindex;
var layerindex2;
var jsonresult;
var jsonD;
var jsonD2;
var xhr;

function loadset() {
    var whost = decodeURIComponent($("#whost").val()).replace(/(http:\/\/[^\/]+\/).*$/, "$1");
    var s_url = $("#s_url").val().replace(/(http:\/\/[^\/]+\/).*$/, "$1")
    if (/zq=[0-9]+\b/gi.test($("#s_url").val())) {
        $("#gather_type").val(6);
    }
    if (whost != s_url) {
        if (ajaxGet0 != null) {
            ajaxGet0.abort();
        }
        var ajaxGet0 = $.ajax({
            type: 'get',
            async: false,//true是异步，false是同步
            timeout: 90000,//90秒
            url: "../../collect/reset/longsun_collect_set.php", //"?rn="+Math.random(),  //网址请以/开头否则可能不带cookies过去
            data: {
                "onlyread": 1,
                "gather_type": o.gather_type.value,
                "url": o.url.value,
                "s": Math.random()
            }, //data里面的值不要有未定认或null值
            dataType: "html",//html,text,json,jsonp,excel,script
            success: function (data) {
                $("#gzdw").html(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg("出错:" + XMLHttpRequest.status);
                layer.close(layerindex);
            }
        });
    }
}

function searchsite() {
    $.get("../../collect/reset/longsun_collect_search.php", {
        onlyread: 1,
        gather_type: o.gather_type.value,
        skey: o.skey.value,
        s: Math.random()
    }, function (data) {
        $("#searchdiv").html(data)
    });
}

function areAllInputsNotFocused() {
    const textareas = document.getElementsByTagName('textarea');
    const inputs = document.getElementsByTagName('input');
    const allElements = Array.from(textareas).concat(Array.from(inputs));
    for (let i = 0; i < allElements.length; i++) {
        if (document.activeElement === allElements[i]) {
            return false;
        }
    }
    return true;
}

//粘贴
document.addEventListener("paste", function (e) {
    if(!areAllInputsNotFocused()) return false;
    var url = e.clipboardData.getData("text")
    if(url.includes('###')){
        const [url, cookie] = clipboardText.split("###");
        $("#tempcookie").val(cookie);
    }
    if (/http[^<>]+/.test(url) && $(':focus').length == 0) {
        if ($("#htmlpageuse").val() != 0) {
            $("#htmlpageuse").val(1);
        }
        urlstr = e.clipboardData.getData("text")
        url = urlstr.match(/http[s]?:\/\/[^\s<>"]+/g)
        $("#s_url").val(url);
        testt(0)
    } else if (/^(POST|GET)\s+([^\s]*)\s+http\//gi.test(url) && $(':focus').length == 0) {
        let nn = /Cookie:\s+([^\r\n]*)/gim.exec(url);
        cookie = nn[1];
        $("#cookie").val(nn[1]);
        nn = /^(POST|GET)\s+([^\s]*)\s+http\//gi.exec(url);
        $("#s_url").val(nn[2]);
        testt(0);
        $.ajax({
            type: 'post',
            async: true,//true是异步，false是同步
            timeout: 200000,//20秒，这里是毫秒
            url: "./json.php?savecookie=1",
            data: {
                "cookie": cookie,
                "url": nn[2]
            },
            dataType: "json",
            success: function (data) {
            }
        });
    } else {
        $("#parset").html(e.clipboardData.getData("text"));
    }
});

function zcgj(o) {
    layer.open({
        type: 2,
        title: '字串工具',
        shadeClose: true,
        area: ['1000px', '380px'],
        content: '../../collect/reset/createstr.php?XDEBUG_SESSION_START=54354&o=' + o //iframe的url
    });
}

function help(o) {
    layer.open({
        type: 2,
        title: '帮助',
        shadeClose: true,
        area: ['1000px', '380px'],
        skin: 'layeroverflowhidden',
        scrollbar: false,
        content: ['../../collect/reset/help.php?o=' + o, 'no'] //iframe的url
    });
}


document.onkeydown = function (e) {
    if (e.ctrlKey && e.keyCode == 67) {//ctrl+C
        function handler(event) {
            event.clipboardData.setData('text/plain', "自定义复制内容");
            document.removeEventListener('copy', handler, true);
            event.preventDefault();
        }

        document.addEventListener('copy', handler, true);
        document.execCommand('copy');
    }
}

$(document).on("click", "#uchome-ifrHtmlEditor img", function () {
    if (!$(this).hasClass("maximg")) {
        $(this).addClass("maximg");
        $("#maximg").css("top", $(top.window).scrollTop());
        $("#maximg").css("margin-left", -$(this).width() / 2);
        $("#maximgdiv").show()
        $("#maximg", top.window.document).attr("src", $(this).attr("src"));
    } else {
        $("#maximgdiv").hide();
        $(this).removeClass("maximg").attr("zoom", "100%");
    }
});

function bbimg(o) {
    var zoom = parseInt(o.style.zoom, 10) || 100;
    zoom += event.wheelDelta / 100;
    console.log(event.wheelDelta);
    if (zoom > 0) {
        o.style.zoom = zoom + '%';
    }
    return false;
}

function fullScreen() {
    var el = document.documentElement;
    var rfs = el.requestFullScreen || el.webkitRequestFullScreen ||
        el.mozRequestFullScreen || el.msRequestFullScreen;
    if (typeof rfs != "undefined" && rfs) {
        rfs.call(el);
    } else if (typeof window.ActiveXObject != "undefined") {
        //for IE，这里其实就是模拟了按下键盘的F11，使浏览器全屏
        var wscript = new ActiveXObject("WScript.Shell");
        if (wscript != null) {
            wscript.SendKeys("{F11}");
        }
    }
}

//浏览器进入全屏模式，兼容IE


$(document).on("click", "#maximg", function (event) {
    if (!$(this).hasClass("maxwidth")) {
        var OldHeightLi = event.offsetY / $(this)[0].height;
        $(this).addClass("maxwidth").show();
        var zjheight = OldHeightLi * $(this)[0].height;
        $(this).css("margin-top", ((window.innerHeight / 2) - zjheight) + "px");
        //fullScreen()
    } else {
        $(this).removeClass("maxwidth");
        $(this).css("margin-top", 0);
    }
});

$(document).on("mouseout", "#maximg", function (event) {
    $("#maximgdiv").hide();
    $(this).removeClass("maximg");
    //fullScreen()
});


$(document).on("click", "#a>span.right>a", function (event) {
    setTimeout(function () {
        document.documentElement.scrollTop -= 35;
    }, 200)
});

function bigimg(obj) {
    var zoom = parseInt(obj.style.zoom, 10) || 100;
    zoom += event.wheelDelta / 12;
    if (zoom > 0)
        obj.style.zoom = zoom + '%';
    return false;
}


function changeUrlWithPage() {
    if (!/\[([0-9]+)-([0-9]+)\]/.test(o.url.value)) return;
    o.url.value.match(/\[([0-9]+)-([0-9]+)\]/);
    if (parseInt(RegExp.$1) < parseInt(RegExp.$2)) {
        url = o.url.value.replace(/\[([0-9]+)-([0-9]+)\]/, page++);
        if (page >= RegExp.$2) return;
    } else {
        url = o.url.value.replace(/\[([0-9]+)-([0-9]+)\]/, page--);
        if (page <= RegExp.$2) return;
    }
    setTimeout(function () {
        alert(url)
    }, 10000);
    doatest(url, 0);
}

$(document).on("click", "#kuaizhao", function () {
    index = layer.load(0, {shade: false});
    if ($("#url").val() != "") {
        $.ajax({
            type: 'get',
            async: true,//true是异步，false是同步
            timeout: 20000,//20秒，这里是毫秒
            url: "reset_api.php?kuaizhao=1",
            data: {
                "s_url": $("#s_url").val()
            },
            dataType: "json",//html,text,json,excel,script
            success: function (data) {
                $("#history").html(data.kuaizhaostr)
                layer.close(index);
            }
        });
    }
})


function doatest(url, wao) {
    var ao = wao;
    var shipin;
    layerindex = layer.load(0, {shade: false, zIndex: 999999});
    $("#uchome-ifrHtmlEditor").html("");
    if (ajaxGet != null) {
        ajaxGet.abort();
    }
    ajaxGet = $.ajax({
        type: 'get',
        async: true,//true是异步，false是同步
        timeout: 90000,//90秒
        url: "../../collect/reset/reset_send.php", //"?rn="+Math.random(),  //网址请以/开头否则可能不带cookies过去
        data: {
            "onlyread": 1,
            "gather_type": o.gather_type.value,
            "s_url": encodeURIComponent(url),
            "nozqnr": nozqnr,
            "zwnozqnr": zwnozqnr,
            "source": 1,
            "htmlpageuse": $("#htmlpageuse").val(),
            "bug": ao,
            "ubb": $("#ubb").prop("checked") ? 0 : 1,
            "temp": $("#temp").prop("checked") ? 1 : 0,
            "cookie": $("#cookie", top.document).val()!=""?$("#cookie", top.document).val():$("#tempcookie", top.document).val(),
            "s": Math.random()
        }, //data里面的值不要有未定认或null值
        dataType: "json",//html,text,json,jsonp,excel,script
        success: function (data) {
            jsonresult = data;
            localStorage.setItem('data', JSON.stringify(data));
            layer.close(layerindex);
            if ($("#htmlpageuse").val() == 1) {
                $("#htmlpageuse").val(2)
            }
            if (typeof (data.retCode) != "undefined") {
                layer.msg(data.retMsg);
                layer.close(layerindex);
                $("#uchome-ifrHtmlEditor").html(data.template);
                return
            }
            if($("#tempcookie").val()!=""){
                $("#cookie").val($("#tempcookie").val());
            }
            $("#B2").removeAttr("disabled");
            $("#subject").val(data.subject);
            if ($("#pbliu").attr("checked")) {
                var json = new Array();
                var patt = new RegExp("\\[img\\]([^<>]+?)\\[\\/img\\]", "gi");
                var result;
                var index = 0;
                while ((result = patt.exec(data.message)) != null) {
                    json[index] = new Array();
                    json[index]['image'] = result[1];
                    json[index]['subject'] = gettitle(result[1], data.message, data.subject);
                    json[index]['url'] = $("#s_url").val();
                    index++;
                }
                loadMore(json, changeUrlWithPage());
            } else {
                cid = data.cid;
                $("#uchome-ttHtmlEditor").val(data.message + "\r\n==========================\r\n" + data.bug + "\r\n简介:" + data.jianjie);
                //data.message = data.message.replace(/\r?\n/gi, "<p>");
                if (data.message == null) {
                    data.message = JSON.stringify(data)
                }
                data.message = data.message.replace(/\[align=center\]/gi, "<p align=center>");
                data.message = data.message.replace(/\[align=left\]/gi, "<p align=left>");
                data.message = data.message.replace(/\[align=right\]/gi, "<p align=right>");
                data.message = data.message.replace(/\[\/align\]/gi, "</p>");
                data.message = data.message.replace(/\[img\](.*?)\[\/img\]/gi, "<img src=\"$1\"/>");
                data.message = data.message.replace(/\[url=([^<>\[\]]+)\](.*?)\[\/url\]/gi, "<a target=_blank href=\"$1\">$2</a>");
                data.message = data.message.replace(/\[img\]/gi, "<img src=\"");
                data.message = data.message.replace(/\[\/img\]/gi, "\">");
                data.message = data.message.replace(/\[b\](.*)\[\/b\]/gi, "<b>$1</b>");
                data.message = data.message.replace(/\[b\]|\[\/b\]/gi, "");
                data.message = data.message.replace(/\[color=([^\[\]]*)\]([\s\S\[\]]*?)\[\/color\]/gi, "<span style=\"color:$1\">$2</span>");
                data.message = data.message.replace(/\[color=([^\[\]]*)\]|\[\/color\]/gi, "");
                data.message = data.message.replace(/\[(\/)?(table|tr|td)\]/gi, "<$1$2>");
                data.message = data.message.replace(/\[(\/)?(table|tr|td)=(\d+%?)\]/gi, "<$1$2 width=$3>");
                data.message = data.message.replace(/\[(\/)?(td)=(\d+),(\d+)\]/gi, "<$1$2 colspan=$3 rowspan=$4>");
                data.message = data.message.replace(/\[(\/)?(td)=(\d+),(\d+),(\d+%?)\]/gi, "<$1$2 colspan=$3 rowspan=$4 width=$5>");
                data.message = data.message.replace(/<p[^<>]*>(\s|<br\s*\/?>|　)*<\/p>/gi, "");
                data.message = data.message.replace(/(<p[^<>]*>\s*<p[^<>]*>){1,}/gi, "<p>");
                if (data.flash != "" && typeof (data.flash) != "undefined") {
                    var viddiv = "";
                    viddiv += "    <div id=\"video\" style=\"width: 100%; margin:0 auto\"></div>";
                    viddiv += "\n    <sc" + "ript type=\"text/javascript\">";
                    viddiv += "\n        var videoObject = {";
                    viddiv += "\n            container: '#video', //容器的ID或className";
                    viddiv += "\n            variable: 'player', //播放函数名称";
                    viddiv += "\n            loop: true, //播放结束是否循环播放";
                    viddiv += "\n            autoplay: true,//是否自动播放";
                    viddiv += "\n            preload:'auto',";
                    viddiv += "\n            //flashplayer:true,  //video/mp4、video/m3u8";
                    viddiv += "\n            live:true,";
                    viddiv += "\n            //debug:true,";
                    viddiv += "\n            video:[";
                    viddiv += "\n                ['" + data.flash + "', 'video/mp4', '中文标清', 0],";
                    viddiv += "\n            ]";
                    viddiv += "\n        };";
                    viddiv += "\n        $(document).ready(function(){var player = new ckplayer(videoObject);})";
                    viddiv += "\n    </scr" + "ipt>";
                } else {
                    viddiv = ""
                }
                var flashdiv = "";
                if (data.flash != "" && typeof (data.flash) != "undefined") {
                    flashdiv = "<p id=\"flashdiv\"><a target=_blank href=\"" + data.flash + "\"><i class=\"fa fa-video-camera\"></i>" + data.flash + "</a></p>";
                }
                data.message = flashdiv + "<p id=\"title2\">" + data.subject2 + "</p><p id=\"title\">" + data.subject + "</p><p id=\"title3\">" + data.subject3 + "</p>\r\n" + "<p id=\"titledi\">" + data.dateline + "&nbsp;" + data.author + "&nbsp;" + data.laiyuan + "&nbsp;" + data.plate + "</p>\r\n" + viddiv + data.message;
                //$("#uchome-ifrHtmlEditor").html(data.message);
                $("#uchome-ifrHtmlEditor")[0].innerHTML = data.message
                var colors = ["orangered", "black", "chocolate", "red", "blue", "blueviolet", "coar", "crimson", "darkorchid", "darkgreen", "darkmagenta", "limegreen", "lightseagreen", "magenta"]
                $("#title,#title2,#title3").css("color", colors[Math.floor(Math.random() * colors.length)]);
                if (layerindex2) layer.close(layerindex2);
                if (viddiv != "" && typeof (data.flash) != "undefined") {
                    layerindex2 = layer.open({
                        type: "iframe",
                        title: '在线调试',
                        content: viddiv,//js2+html+
                        area: ['520px', '365px'],
                        zIndex: 3,
                        shade: 0,
                    });
                    layer.close(layerindex2);
                }
            }
            $("#dateline").val(data.dateline);
            $("#replies").val(data.replies);
            $("#views").val(data.views);
            $("#plate").val(data.plate);
            $("#keywordv").val(data.keyword);
            $("#laiyuan").val(data.laiyuan);
            $("#author").val(data.author);
            $("#jizhe").val(data.jizhe);
            $("#swf").val(data.flash);
            $("#aviimage").val(data.aviimage);
            if (data.hasOwnProperty('thumb')) $("#faceimg").val(data.thumb[0]);
            $("#resource").val(data.resources);
            $("#subject2").val(data.subject2);
            $("#subject3").val(data.subject3);
            $("#jianjie").val(data.jianjie);
            $("#yan").val(data.source);
            $("#cacheid").text(data.cacheid);
            $("#elementinfo").html(data.elementinfo);

            $("#dologin").attr("href", "dologin://" + $("#this_host").val() + "/");
            if (data.hasOwnProperty('rs') && data.rs) {
                $("#hostid").text(data.rs.id);
                if (data.rs.getcontenttype) $("select[name='getcontenttype']").val(data.rs.getcontenttype)
                if (data.rs.nrzq != null) {
                    var nn = data.rs.nrzq.split(/,/g);
                    $("input[name='nrzq[]']").prop("checked", false)
                    for (var i = 0; i < nn.length; i++) {
                        if (nn[i] != "") $("#nrzq" + nn[i]).prop("checked", true)
                    }
                }
                if (data.rs.listzq != null) {
                    var nn = data.rs.listzq.split(/,/g);
                    $("input[name='listzq[]']").prop("checked", false)
                    for (var i = 0; i < nn.length; i++) {
                        if (nn[i] != "") $("#lizq" + nn[i]).prop("checked", true)
                    }
                }
                $("#pq").val(data.rs.pq)
                $("#pp_subject").val(data.rs.titlere)
            }
            bugmessage(data.bug);
            popjksjck()
            if (ao == 2) {
                layer.tips(data[ob], '#pp_' + ob, {
                    tips: [1, '#000'],
                    closeBtn: 1,
                    shadeClose: true,
                    area: 'auto',
                    maxWidth: 1000,
                    maxHeight: 350,
                    zIndex: 999,
                    time: 5000,
                });
                showTips();
                return false;
            } else {
                showTips();
            }

        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.msg("出错:" + XMLHttpRequest.status);
            layer.close(layerindex);
        },
        complete: function (XMLHttpRequest, status) {
            if (status == 'timeout') {
                //超时,status还有success,error等值的情况
                layer.msg("超时:" + status);
                layer.close(layerindex);
            } else {
                layer.msg("完成:" + status);
                layer.close(layerindex);
            }
        }
        //,cache:false, // disable cache(禁用IE缓存)
        //,ifModified:true
    });


    // ajaxGet2 = $.ajax({
    //     type: 'get',
    //     async: true,//true是异步，false是同步
    //     timeout: 90000,//90秒
    //     url: "reset_api.php?gethistorys=1", //"?rn="+Math.random(),  //网址请以/开头否则可能不带cookies过去
    //     dataType: "json",//html,text,json,jsonp,excel,script
    //     data: {
    //         "s_url": url,
    //     },
    //     success: function (data) {
    //         $("#history").html(data.str)
    //     },
    // })
}

$(document).on("click", "#guocheng", function () {
    bugmessage();
})

$(document).on("click", "#jksjck", function () {
    popjksjck();
})

function bugmessage(message) {
    if (message == null) {
        data = JSON.parse(localStorage.getItem('data'));
        message = data.bug
    }
    if ($("#guocheng").prop("checked") && $("#layui-layer" + jsonD2).length < 1) {
        jsonD2 = layer.open({
            type: 1,
            title: '执行过程 浏览窗口',
            closeBtn: 1,
            shade: 0,
            area: [($(window).width() * 0.49) + "px", ($(window).height() * 0.99 / 2) + "px"],
            offset: [
                $(window).height() * 0.99 / 2 + "px",
                $("#uchome-ifrHtmlEditor", top.document).offset().left + "px"
            ], //左上角弹出
            anim: 2,
            maxmin: true,
            content: "<textarea style=\"width:100%;height:100%\">" + message + "</textarea>",
            end: function () {
                $('#guocheng').prop("checked", false);
            }
        });
    } else if (!$("#guocheng").prop("checked")) {
        layer.close(jsonD2);
    }
}

function popjksjck() {
    if ($("#jksjck").prop("checked") && $("#layui-layer" + jsonD).length < 1) {
        jsonD = layer.open({
            type: 2,
            title: '接口/数据 浏览窗口',
            closeBtn: 1,
            shade: 0,
            area: [($(window).width() * 0.49) + "px", ($(window).height() - 45) + "px"],
            offset: 'rb', //左上角弹出
            anim: 2,
            maxmin: true,
            content: ['html/apijson.html'],
            end: function () {
                $('#jksjck').prop("checked", false);
                delcookie('v')
            }
        });
        layer.style(jsonD, {
            'opacity': '0.4',
            'filter': 'alpha(opacity=40)',
            'resize': 'both',
            'overflow': 'auto'
        });
    } else if ($("#jksjck").prop("checked") && jsonD > 0) {
        $("#layui-layer-iframe" + jsonD)[0].contentWindow.document.location.reload()
    } else if (!$("#jksjck").prop("checked")) {
        layer.close(jsonD);
    }
}

function dostop() {
    if (ajaxGet != null && ajaxGet.readyState != 4) {
        ajaxGet.abort();
    }
    // $.ajax("clear.php?XDEBUG_SESSION_START=20200702114651",function(data){
    //         alert(1)
    // })
    layer.close(layerindex);
    $("#B2").removeAttr("disabled");
    return false;
}

function showTips() {
    $(".cheshi").each(function () {
        obi = $(this).attr("ob");
        if ($("#" + obi).val() != null && $("#" + obi).val().substr(0, 4) == "http") {
            $('#tip_' + obi).css("color", "#4688F1").css("font-weight", "bold").html("<a target=_blank style=\"color: rgb(70, 136, 241);\" href=\"" + $("#" + obi).val() + "\">" + $("#" + obi).val().substr(0, 80) + "..." + $("#" + obi).val().substr(-15, 15) + "</a>");
        } else {
            $('#tip_' + obi).css("color", "#4688F1").css("font-weight", "bold").text($("#" + obi).val());
        }
    })
}


function count(o) {
    var t = typeof o;
    if (t == 'string') {
        return o.length;
    } else if (t == 'object') {
        var n = 0;
        for (var i in o) {
            n++;
        }
        return n;
    }
    return false;
}

function fz(o) {
    var s = o.innerHTML.replace(/\&amp\;/gi, "&");
    $("input[name=url]").val(s);
    testt(0);
}

function openimg(url, o) {
    layer.open({
        type: 2,
        title: false,
        area: ['95%', '100%'],
        shade: 0.8,
        closeBtn: 0,
        shadeClose: true,
        content: url
    });
}

function gettitle(url, nr, bt) {
    var re = new RegExp("==[\\r\\n\\s]*((?:[^=\\r\\n](?!==))*)[\\r\\n](?:[\\S\\s](?!==))*" + addsla(url), "gi");
    if ((result = re.exec(nr)) != null) {
        return result[1].replace(/^\s/, '');
    } else {
        return bt;
    }
}

function addsla(str) {
    str = str.replace(/([\.\/\?\:\&])/g, "\\$1");
    return str;
}

function onsurlchange() {
    var eu = encodeURIComponent($("#s_url", window.parent.document).val());
    loadset();
}

function qk() {
    $("#uchome-ifrHtmlEditor").html("");
    $("#stage>li").html("");
}

function parseUrl() {
    var cont = getClipboard();
    alert(count)
    $("#s_url").val(cont);
}

function setClipboard(maintext) {
    if (window.clipboardData) {
        return (window.clipboardData.setData("Text", maintext));
    } else if (window.netscape) {
        netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
        var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
        if (!clip) return;
        var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
        if (!trans) return;
        trans.addDataFlavor('text/unicode');
        var str = new Object();
        var len = new Object();
        var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
        var copytext = maintext;
        str.data = copytext;
        trans.setTransferData("text/unicode", str, copytext.length * 2);
        var clipid = Components.interfaces.nsIClipboard;
        if (!clip) return false;
        clip.setData(trans, null, clipid.kGlobalClipboard);
        return true;
    }
    return false;
}

function getClipboard() {
    if (window.clipboardData) {
        return (window.clipboardData.getData('Text'));
    } else if (window.netscape) {
        try {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        } catch (e) {
            alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将 'signed.applets.codebase_principal_support'设置为'true'");
        }
        netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
        var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
        if (!clip) return;
        var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
        if (!trans) return;
        trans.addDataFlavor('text/unicode');
        clip.getData(trans, clip.kGlobalClipboard);
        var str = new Object();
        var len = new Object();
        try {
            trans.getTransferData('text/unicode', str, len);
        } catch (error) {
            return null;
        }
        if (str) {
            if (Components.interfaces.nsISupportsWString) strstr = str.value.QueryInterface(Components.interfaces.nsISupportsWString);
            else if (Components.interfaces.nsISupportsString) strstr = str.value.QueryInterface(Components.interfaces.nsISupportsString);
            else str = null;
        }
        if (str) {
            return (str.data.substring(0, len.value / 2));
        }
    }
    return null;
}

$(document).on('dblclick', '.cheshi', function () {
    index = layer.msg("正在测试...");
    submits();
    ob = $(this).attr("ob");
    top.testt(2);
})

$(document).on('dblclick', '.history', function () {
    var that = $(this);
    ajaxGet2 = $.ajax({
        type: 'get',
        async: true,//true是异步，false是同步
        timeout: 90000,//90秒
        url: "reset_api.php?gethistory=1", //"?rn="+Math.random(),  //网址请以/开头否则可能不带cookies过去
        dataType: "html",//html,text,json,jsonp,excel,script
        data: {
            "id": $("#history>option:selected").attr("value"),
            "fieldname": $(that).attr("name")
        },
        success: function (html) {
            var oriHeight = $(that).height() + "px"
            var oriWidth = $(that).width() + 55 + "px"
            $(that)[0].style.height = 'auto';
            $(that)[0].scrollTop = 0;
            $(that)[0].style.height = $(that)[0].scrollHeight + 'px';
            var afterWidth = $(that)[0].style.height
            var after2Width = $(that).height() + 80 + "px";
            $(that).css("height", afterWidth);
            layer.open({
                type: 1,
                closeBtn: true, //不显示关闭按钮
                shift: 1,
                shadeClose: true, //开启遮罩关闭
                area: [oriWidth, after2Width],
                content: html,
                end: function () {
                    $(that).css("height", oriHeight);
                }
            });
        },
    })


})

$(document).on('click', '#paibanhtml', function () {
    var that = $(this);
    index = layer.load(0, {shade: false, zIndex: 999999});
    ajaxGet2 = $.ajax({
        type: 'post',
        async: true,//true是异步，false是同步
        timeout: 90000,//90秒
        url: "reset_api.php?htmlnice=1", //"?rn="+Math.random(),  //网址请以/开头否则可能不带cookies过去
        dataType: "html",//html,text,json,jsonp,excel,script
        data: {
            "code": $("#yan").val()
        },
        success: function (html) {
            layer.close(index)
            $("#yan").val(html)
        },
    })
})

$(document).on('click', '#getcookie', function () {
    var that = $(this);
    index = layer.load(0, {shade: false, zIndex: 999999});
    ajaxGet2 = $.ajax({
        type: 'post',
        async: true,//true是异步，false是同步
        timeout: 90000,//90秒
        url: "reset_api.php?getcookie=1", //"?rn="+Math.random(),  //网址请以/开头否则可能不带cookies过去
        dataType: "html",//html,text,json,jsonp,excel,script
        data: {
            "host": $("#this_host").val()
        },
        success: function (html) {
            layer.close(index)
            $("#cookie").val(html.trim())
        },
    })
})
$(document).on('click', '#loginsetup', function () {
    if ($('#loginsetup').prop("checked") == true) {
        $("#loginsetupdiv").show();
    } else {
        $("#loginsetupdiv").hide();
    }
})

$(document).on('click', '#maxwin', function () {
    var that = $(this);
    layer.open({
        type: 1,
        skin: 'layui-layer-demo',
        area: ['100%', '95%'], //宽高
        shift: 2,
        shadeClose: false, //开启遮罩关闭
        closeBtn: 1,
        content: "<textarea style='width: 100%;height:100%'>" + $("#yan").val() + "</textarea>"
    });
})
$(document).on("dblclick", ".layui-layer-title", function () {
    layer.close()
})

$(document).on("mouseover", "#dologin", function () {
    $("#dologin").attr("href", "dologin://" + $("#this_host").val() + "/");
})

$(document).on('mouseover', '#cache_before', function () {
    data = JSON.parse(localStorage.getItem('data'));
    $(this).attr("href", "/collect/reset/viewhtml.php?cid=" + data.cid + "&n=element_before");
})

$(document).on('click', '#cache_before_code', function () {
    index = layer.load(0, {shade: false, zIndex: 999999});
    data = JSON.parse(localStorage.getItem('data'));
    $.ajax({
        type: 'get',
        async: true,//true是异步，false是同步
        timeout: 90000,//90秒
        url: "../../collect/reset/viewhtml.php?url=" + encodeURIComponent($("#s_url").val()) + "&n=element_before", //"?rn="+Math.random(),  //网址请以/开头否则可能不带cookies过去
        dataType: "html",//html,text,json,jsonp,excel,script
        success: function (html) {
            layer.close(index);
            $("#yan").val(html)
        },
    })
})

$(document).on('mouseover', '#cache_after', function () {
    data = JSON.parse(localStorage.getItem('data'));
    $(this).attr("href", "../../collect/reset/viewhtml.php?url=" + encodeURIComponent($("#s_url").val()) + "&n=tempnr");
})

$(document).on('click', '#cache_after_code', function () {
    index = layer.load(0, {shade: false, zIndex: 999999});
    data = JSON.parse(localStorage.getItem('data'));
    $.ajax({
        type: 'get',
        async: true,//true是异步，false是同步
        timeout: 90000,//90秒
        url: "../../collect/reset/viewhtml.php?url=" + encodeURIComponent($("#s_url").val()) + "&n=tempnr",  //网址请以/开头否则可能不带cookies过去
        dataType: "html",//html,text,json,jsonp,excel,script
        success: function (html) {
            layer.close(index);
            if (html == "") {
                layer.msg("没有数据！")
            } else {
                $("#yan").val(html)
            }
        },
    })
})

$(document).on('click', '#jsdata', function () {
    index = layer.load(0, {shade: false, zIndex: 999999});
    data = JSON.parse(localStorage.getItem('data'));
    if (!typeof (data.addreturn) && !typeof (data.addreturn).jsdata) {
        var jsdata = data.addreturn.jsdata;
    } else {
        $.ajax({
            type: 'get',
            async: true,//true是异步，false是同步
            timeout: 90000,//90秒
            url: "../../collect/reset/viewhtml.php?cid=" + data.cid + "&n=jsdata",  //网址请以/开头否则可能不带cookies过去
            dataType: "html",//html,text,json,jsonp,excel,script
            success: function (html) {
                layer.close(index);
                if (html == "") {
                    layer.msg("没有数据！")
                } else {
                    $("#yan").val(html)
                }
            },
        })
        layer.close(index);
        return false;
    }
    $.ajax({
        type: 'POST',
        async: true,//true是异步，false是同步
        timeout: 90000,//90秒
        url: "../../collect/reset/json_test.php", //"?rn="+Math.random(),  //网址请以/开头否则可能不带cookies过去
        dataType: "html",//html,text,json,jsonp,excel,script
        data: {
            code: jsdata,
        },
        success: function (html) {
            layer.close(index);
            $("#yan").val(html)
        },
    })
})

$(document).on('click', '#jksjck', function () {
    if ($(this).prop("checked")) {
        setcookie('v', 1)
    } else {
        delcookie('v')
    }
})

var HtmlUtil = {
    /*1.用浏览器内部转换器实现html转码*/
    htmlEncode: function (html) {
        //1.首先动态创建一个容器标签元素，如DIV
        var temp = document.createElement("div");
        //2.然后将要转换的字符串设置为这个元素的innerText(ie支持)或者textContent(火狐，google支持)
        (temp.textContent != undefined) ? (temp.textContent = html) : (temp.innerText = html);
        //3.最后返回这个元素的innerHTML，即得到经过HTML编码转换的字符串了
        var output = temp.innerHTML;
        temp = null;
        return output;
    },
    /*2.用浏览器内部转换器实现html解码*/
    htmlDecode: function (text) {
        //1.首先动态创建一个容器标签元素，如DIV
        var temp = document.createElement("div");
        //2.然后将要转换的字符串设置为这个元素的innerHTML(ie，火狐，google都支持)
        temp.innerHTML = text;
        //3.最后返回这个元素的innerText(ie支持)或者textContent(火狐，google支持)，即得到经过HTML解码的字符串了。
        var output = temp.innerText || temp.textContent;
        temp = null;
        return output;
    }
};

$(document).on("click", "#zuanyue", function () {
    if ($("#pp_jsonHost").hasClass("height_suoxiao")) {
        $("#cookieWin,#pp_jsonHost").removeClass("height_suoxiao");
        $("#pp_jsonHost").addClass("height_zankai");
        $("#viewresult dd:not(#sourceWin)").hide();
        $("#peizhi dd:not(#proWin):not(#eleWin)").hide();
        $("#proWin,#eleWin").show();
        $("#yan").css("height", "450px");
        if(!$("#isselector").prop("checked")) {
            $.ajax({
                type: 'post',
                async: true,//true是异步，false是同步
                timeout: 20000,//20秒
                url: "/collect/reset/json.php", //"?rn="+Math.random(),  //网址请以/开头否则可能不带cookies过去
                data: {url: $("#s_url").val(), filters: $("#pp_jsonHost").val(), getArr: 1},  //$("form").serialize()
                dataType: "json",//html,text,json,jsonp,excel,script
                success: function (data) {
                    if(typeof data.filters!="undefined"&& data.filters!="") {
                        $("#pp_jsonHost").val(data.filters);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    debugger;
                }
            });
        }
    }else{
        $("#cookieWin,#pp_jsonHost").removeClass("height_zankai");
        $("#pp_jsonHost").addClass("height_suoxiao")
        $("#viewresult dd:not(#sourceWin)").show();
        $("#peizhi dd:not(#proWin):not(#eleWin)").show();
        $("#yan").css("height", "289px");
    }
});

$(document).on("click", "#cookieshref", function () {
    if ($("#cookieWin").hasClass("height_suoxiao")) {
        $("#cookieWin,#pp_jsonHost").removeClass("height_suoxiao");
        $("#cookieWin").addClass("height_zankai");
        $("#cookie").css("height","224px");
        $("#viewresult dd:not(#sourceWin)").hide();
        $("#peizhi dd:not(#cookieWin)").hide();
        $("#yan").css("height", "450px");
    }else{
        $("#cookieWin,#pp_jsonHost").removeClass("height_zankai");
        $("#cookieWin").addClass("height_suoxiao")
        $("#viewresult dd:not(#cookieWin)").show();
        $("#peizhi dd:not(#sourceWin)").show();
        $("#cookie").css("height","150px");
        $("#yan").css("height", "289px");
    }
});

$(document).on("click", "#yanshref", function () {
    if ($("#sourceWin").hasClass("height_suoxiao")) {
        $("dd").removeClass("height_suoxiao");
        $("#viewresult dd,#peizhi dd").hide();
        $("#sourceWin").addClass("height_zankai")
        $("#sourceWin").show();
        $("#yan").css("height", "800px");
    }else{
        $("dd").removeClass("height_zankai");
        $("#viewresult dd,#peizhi dd").show();
        $("#sourceWin").addClass("height_suoxiao")
        $("#yan").css("height", "200px");
    }
});


$(document).on("click", "#zuanyuesj", function () {
    if($("#cookie")){
        cookie=$("#cookie").val();
    }else{
        cookie=$("#tempcookie").val();
    }
    json=window.open("https://collect.yangjc.com/collect/reset/json.php?s_url="+encodeURIComponent($("#s_url").val())+"&cookie="+cookie,"json");
});


$(document).on("blur", "#pp_jsonHost", function () {
    if(!$("#isselector").prop("checked")) {
        $.ajax({
            type: 'post',
            async: true,//true是异步，false是同步
            timeout: 20000,//20秒
            url: "/collect/reset/json.php", //"?rn="+Math.random(),  //网址请以/开头否则可能不带cookies过去
            data: {url: $("#s_url").val(), filters: $("#pp_jsonHost").val(), saveFilters: 1},  //$("form").serialize()
            dataType: "json",//html,text,json,jsonp,excel,script
            success: function (data) {
                if(typeof data.filters!="undefined"&& data.filters!="") {
                    $("#pp_jsonHost").val(data.filters);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                debugger;
            }
        });
    }
    $("#viewresult dd:not(#sourceWin)").hide();
    $("#peizhi dd:not(#proWin):not(#eleWin)").hide();
});

$(document).on("click", "#savecache", function () {
        $.ajax({
            type: 'post',
            async: true,//true是异步，false是同步
            timeout: 20000,//20秒
            url: "/collect/reset/savecache.php", //"?rn="+Math.random(),  //网址请以/开头否则可能不带cookies过去
            data: {url: $("#s_url").val(), yuannr: $("#yan").val(),cacheid:$("#cacheid").text()},  //$("form").serialize()
            dataType: "json",//html,text,json,jsonp,excel,script
            success: function (data) {
                layer.msg(data.msg+"!!!");
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                debugger;
            }
        });
});

